package com.example.springboot_demo.dao;

import com.example.springboot_demo.mappers.UserMapper;
import com.example.springboot_demo.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component("UserDao")
public class UserDao {
    @Autowired
    private UserMapper userMapper;

    //增加用户
    public void registerUser(User user) {
        userMapper.registerUser(user);
    }

    //删除用户
    public void deleteUser(User user) {

        //使用mybatis
        userMapper.deleteUser(user);
        userMapper.dropIdColumn();
        userMapper.addIdColumn();
    }

    //检查登录
    public User checkLogin(User user) {

        //mybatis mapper代理开发
        User user1 = userMapper.checkLogin(user);
        return user1;
    }

    //获取user的生日
    public String getUserDate(User user) {
        String date = userMapper.getUserDate(user);
        return date;
    }

    //查询用户
    public User inquire(User user) {

        //mybatis mapper代理开发
        User user1 = userMapper.inquire(user);
        return user1;
    }

    //通过用户名查询用户
    public User getUserByName(String userName){
        User user=userMapper.getUserByName(userName);
        return user;
    }

    //修改密码
    public void updatePasswordByName(String userName,String userPassWord) {
        userMapper.updatePasswordByName(userName,userPassWord);
    }


    //查询数据库，判断该用户是否为管理员
    public int isAdmin(User user) {
        int isAdmin = userMapper.isAdmin(user);
        return isAdmin;
    }

}
